package com.yao.springcloud;

import java.util.concurrent.atomic.AtomicLong;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@EnableConfigServer
@SpringBootApplication
@RestController
public class ConfigServerApplication {

	private static final Logger logger = LoggerFactory.getLogger(ConfigServerApplication.class);

	@Value("${spring.application.name}")
	private String servername;

	@Value("${server.port}")
	private String port;

	@Value("${version:[1234-default]}")
	private String version1;

	public static void main(String[] args) {
		SpringApplication.run(ConfigServerApplication.class, args);
		// test();

		AtomicLong content = new AtomicLong();

		for (int i = 0; i < 10; i++) {

			System.out.println(content.incrementAndGet());
		}

	}

	@Bean
	public CommandLineRunner runner() {
		logger.info("===========服务[{} {}]启动完成, 版本号是：{}===========", servername, port, version1);
		return null;
	}
	
	
	
	
	
	
	
	
	
	
	
	

	NativeEnvironmentRepository env;
	
	@Autowired
	CacheProperties cacheProperties;
	
	@RequestMapping(value="getproperty")
	public void getProperty() {
//		System.out.println("logger : "+env.getLocations("module", "test", "master"));
		System.out.println("url : "+cacheProperties.getUrl());
	}
}
